package util;

import java.util.ArrayList;
import java.util.List;

public class PermutationsGenerator {
    private int[] source;
    private int variationLength;
 
    public PermutationsGenerator(int[] source, int variationLength) {
        this.source = source;
        this.variationLength = variationLength;
    }
 
    public List<String> getVariations() {
        int srcLength = source.length;
        int permutations = (int) Math.pow(srcLength, variationLength);
 
        int[][] table = new int[permutations][variationLength];
 
        for (int i = 0; i < variationLength; i++) {
            int t2 = (int) Math.pow(srcLength, i);
            for (int p1 = 0; p1 < permutations;) {
                for (int al = 0; al < srcLength; al++) {
                    for (int p2 = 0; p2 < t2; p2++) {
                        table[p1][i] = source[al];
                        p1++;
                    }
                }
            }
        }
        List<String> result = new ArrayList<String>();
        for (int i = 0; i < table.length; i++) {
        	String s = "";
        	for (int j = 0; j < table[i].length; j++) {
        		s += table[i][j];
        	}
        	result.add(s);
        }
        return result;
    }
}
